using ServiceStack;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
public static class DictionaryExtensions
{
	public static TValue GetValueOrDefault<TValue, TKey>(this Dictionary<TKey, TValue> dictionary, TKey key)
	{
		if (!dictionary.ContainsKey(key))
		{
			return default(TValue);
		}
		return dictionary[key];
	}
	public static void ForEach<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, Action<TKey, TValue> onEachFn)
	{
		foreach (KeyValuePair<TKey, TValue> current in dictionary)
		{
			onEachFn(current.Key, current.Value);
		}
	}
	public static bool UnorderedEquivalentTo<K, V>(this IDictionary<K, V> thisMap, IDictionary<K, V> otherMap)
	{
		if (thisMap == null || otherMap == null)
		{
			return thisMap == otherMap;
		}
		if (thisMap.Count != otherMap.Count)
		{
			return false;
		}
		foreach (KeyValuePair<K, V> current in thisMap)
		{
			V v;
			if (!otherMap.TryGetValue(current.Key, out v))
			{
				bool result = false;
				return result;
			}
			if (!object.Equals(current.Value, v))
			{
				bool result = false;
				return result;
			}
		}
		return true;
	}
	public static List<T> ConvertAll<T, K, V>(IDictionary<K, V> map, Func<K, V, T> createFn)
	{
		List<T> list = new List<T>();
		map.Each(delegate(KeyValuePair<K, V> kvp)
		{
			list.Add(createFn(kvp.Key, kvp.Value));
		});
		return list;
	}
	public static V GetOrAdd<K, V>(this Dictionary<K, V> map, K key, Func<K, V> createFn)
	{
		V result;
		lock (map)
		{
			V v;
			if (!map.TryGetValue(key, out v))
			{
				v = (map[key] = createFn(key));
			}
			result = v;
		}
		return result;
	}
	public static KeyValuePair<TKey, TValue> PairWith<TKey, TValue>(this TKey key, TValue value)
	{
		return new KeyValuePair<TKey, TValue>(key, value);
	}
	public static ConcurrentDictionary<TKey, TValue> ToConcurrentDictionary<TKey, TValue>(this IDictionary<TKey, TValue> from)
	{
		ConcurrentDictionary<TKey, TValue> concurrentDictionary = new ConcurrentDictionary<TKey, TValue>();
		foreach (KeyValuePair<TKey, TValue> current in from)
		{
			concurrentDictionary[current.Key] = current.Value;
		}
		return concurrentDictionary;
	}
}
